﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace VirtualTournaments.Frontend.MenuControls.TournamentManagerMenu
{
    public partial class TournamentManagerMenu : System.Web.UI.UserControl
    {
        private const short MainMenuViewIndex = 0;
        private const short CreateTournamentViewIndex = 1;
        private const short CreateTeamViewIndex = 2;
        private const short CreatePlayerViewIndex = 3;
        private const short PlayMenuControlIndex = 4;
        private const short ViewAllViewIndex = 5;
                
        public EventHandler GoBackButtonClickedBridge;

        protected void Page_Load(object sender, EventArgs e)
        {
            this.MainMenuControl.GoBackButtonClicked += new EventHandler(TournamentManagerMenu_GoBackButtonClicked);
            this.MainMenuControl.GoToPlayMenuClicked += new EventHandler(TournamentManagerMenu_GoToPlayMenuButtonClicked);
            this.PlayMenuControl.GoBackButtonClicked += new EventHandler(TournamentManagerMenu_GoBackButtonClicked);
            this.MainMenuControl.GoToCreateTournamentClicked += new EventHandler(TournamentManagerMenu_GoToCreateTournamentMenuButtonClicked);
            this.CreateTournamentControl.GoBackButtonClicked += new EventHandler(TournamentManagerMenu_GoBackButtonClicked);
        }

        private void TournamentManagerMenu_GoBackButtonClicked(object sender, EventArgs e)
        {
            //TODO: find a better way to do this
            VirtualTournamentsFrontendEvent realEvent = e as VirtualTournamentsFrontendEvent;

            if (realEvent != null)
                if (realEvent.SenderMenu.Equals("TournamentManagerMainMenu"))
                    GoBackButtonClickedBridge(this, new VirtualTournamentsFrontendEvent { SenderMenu = "TournamentManagerMenu" });
                else if (realEvent.SenderMenu.Equals("PlayMenu"))
                    this.TournamentManagerViewControler.ActiveViewIndex = MainMenuViewIndex;
                else if (realEvent.SenderMenu.Equals("CreateTournamentMenu"))
                    this.TournamentManagerViewControler.ActiveViewIndex = MainMenuViewIndex;
        }

        private void TournamentManagerMenu_GoToPlayMenuButtonClicked(object sender, EventArgs e) 
        {
            this.TournamentManagerViewControler.ActiveViewIndex = PlayMenuControlIndex;
        }

        private void TournamentManagerMenu_GoToCreateTournamentMenuButtonClicked(object sender, EventArgs e)
        {
            //this.CreateTournamentControl.AvailableTeamsList.Add("Team1");
            this.TournamentManagerViewControler.ActiveViewIndex = CreateTournamentViewIndex;
        }

    }
}